package com.lanou.zhihu.service.impl;

import com.lanou.zhihu.entity.Question;
import com.lanou.zhihu.mapper.QuestionMapper;
import com.lanou.zhihu.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by QuChao on 2018/10/25.
 */
@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Map<String, Object> add(Question question) {
        Map<String, Object> map = new HashMap<>();
        Integer result = questionMapper.insert(question);
        if (result == 1) {
            map.put("flag", true);
        } else {
            map.put("flag", false);
        }
        map.put("qid", question.getId());
        return map;
    }

    @Override
    public List<Question> findAll() {
        List<Question> questionList = questionMapper.findAll();
        return questionList;
    }

    @Override
    public Question findById(Integer id) {
        Question question = questionMapper.findById(id);
        return question;
    }

    @Override
    public List<Question> findByTid(Integer tid) {
        List<Question> questionList = questionMapper.findByTid(tid);
        return questionList;
    }
}
